package cn.virens.common.boot.mybatis.autoconfig;

import cn.virens.common.mybatis.mapper.mybatis.MybatisDynamicTableNameInterceptor;
import cn.virens.common.mybatis.mapper.mybatis.MybatisModelOperTimeInterceptor;
import cn.virens.common.util.exception.APIException;
import org.mybatis.spring.boot.autoconfigure.ConfigurationCustomizer;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.context.annotation.Bean;

/**
 * Mybatis 添加自定义插件
 */
@AutoConfiguration
public class SimpleMybatisAutoConfig {
    @Bean
    public ConfigurationCustomizer mybatisConfigurationCustomizer() throws APIException {
        return (org.apache.ibatis.session.Configuration configuration) -> {
            configuration.addInterceptor(new MybatisDynamicTableNameInterceptor());
            configuration.addInterceptor(new MybatisModelOperTimeInterceptor());
        };
    }
}
